package com.wufan.day02;

import java.util.Arrays;

/**
 * 数组操作工具类
 * @author SongWufan
 * @date 2021/3/5 22:04
 */
public class ArraysTest {
    public static void main(String[] args) {
        //1.判断是否相等
        int[] arr = new int[]{1,2,3,4};
        int[] arr1 = new int[]{1,3,2,4};
        boolean isEquals = Arrays.equals(arr,arr1);
        System.out.println(isEquals);

        //2.输出数组信息
        System.out.println(Arrays.toString(arr));

        //3.指定值填充到数组
        Arrays.fill(arr1,0,4,1);
        System.out.println(Arrays.toString(arr1));

        //4.对数组进行排序
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        //5.二分查找
        int[] arr2 = new int[]{-98,-34,2,34,54,66,79,105,210,333};
        int i = Arrays.binarySearch(arr2, 1);
        if (i >= 0){
            System.out.println(i);
        }
        else {
            System.out.println("未找到");
        }
    }
}
